# -*- coding: utf-8 -*-
# Scrapy settings for BiliBiliSpider project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://docs.scrapy.org/en/latest/topics/settings.html
#     https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://docs.scrapy.org/en/latest/topics/spider-middleware.html

BOT_NAME = 'BiliBiliSpider'

SPIDER_MODULES = ['BiliBiliSpider.spiders']
NEWSPIDER_MODULE = 'BiliBiliSpider.spiders'

# Crawl responsibly by identifying yourself (and your website) on the user-agent
# USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 Edg/93.0.961.52'

# 日志文件, 本来输出在终端(控制台)的信息，写入到了log文件中
LOG_FILE = "bilibili_spider.log"

# 设置导出编码
FEED_EXPORT_ENCODING = "utf-8"

# Obey robots.txt rules
ROBOTSTXT_OBEY = False

# Configure maximum concurrent requests performed by Scrapy (default: 16)
# CONCURRENT_REQUESTS = 32

# Configure a delay for requests for the same website (default: 0)
# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
# DOWNLOAD_DELAY = 3
# The download delay setting will honor only one of:
# CONCURRENT_REQUESTS_PER_DOMAIN = 16
# CONCURRENT_REQUESTS_PER_IP = 16

# Disable cookies (enabled by default)
# COOKIES_ENABLED = False

# Disable Telnet Console (enabled by default)
# TELNETCONSOLE_ENABLED = False

# Override the default request headers:
# DEFAULT_REQUEST_HEADERS = {
#     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
#     'Accept-Language': 'en',
# }

# Enable or disable spider middlewares
# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html
# SPIDER_MIDDLEWARES = {
#    'BiliBiliSpider.middlewares.BilibilispiderSpiderMiddleware': 543,
# }

# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
DOWNLOADER_MIDDLEWARES = {
    # 'BiliBiliSpider.middlewares.BilibilispiderDownloaderMiddleware': 543,
    # 'BiliBiliSpider.middlewares.RandomUserAgentDownloaderMiddleware': 300,
}

# Enable or disable extensions
# See https://docs.scrapy.org/en/latest/topics/extensions.html
# EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
# }

# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
    # 'BiliBiliSpider.pipelines.BilibilispiderPipeline': 300,
    # 'BiliBiliSpider.pipelines.DownloadVideoPipeline': 305,
    # 'BiliBiliSpider.pipelines.DownloadAudioPipeline': 301,
    # 'BiliBiliSpider.pipelines.SaveMysqlPipeline': 330,
    # 'BiliBiliSpider.pipelines.MergeVideoPipeline': 320,
    # 'BiliBiliSpider.pipelines.TencentSpiderPipeline': 300,
    # 'BiliBiliSpider.pipelines.DownloadTxVideoPipeline': 340,
    # 'scrapy_redis.pipelines.RedisPipeline': 300
}

# Enable and configure the AutoThrottle extension (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/autothrottle.html
# AUTOTHROTTLE_ENABLED = True
# The initial download delay
# AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
# AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
# AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
# AUTOTHROTTLE_DEBUG = False

# Enable and configure HTTP caching (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
# HTTPCACHE_ENABLED = True
# HTTPCACHE_EXPIRATION_SECS = 0
# HTTPCACHE_DIR = 'httpcache'
# HTTPCACHE_IGNORE_HTTP_CODES = []
# HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'

# 多个爬虫文件一起运行
COMMANDS_MODULE = 'BiliBiliSpider.commands'

# 视频下载地址
FILES_STORE = 'videos/'

# MySQL数据库
HOST = 'localhost'
USER = 'root'
PASSWORD = 'password'
# bilibili数据库
DATABASE = 'spider_video'
# tencent数据库
TX_DATABASE = 'tencent_video'
# 优酷数据库
YK_DATABASE = 'youku_video'

# 以下就是分布式的部署
# redis分布式
# 重新指定调度器: 启用Redis调度存储请求队列
SCHEDULER = "scrapy_redis.scheduler.Scheduler"
#
# # 重新指定去重机制: 确保所有的爬虫通过Redis去重
DUPEFILTER_CLASS = "scrapy_redis.dupefilter.RFPDupeFilter"
#
# # 不清除Redis队列: 暂停/恢复/断点续爬
SCHEDULER_PERSIST = True

# 无密码登录
REDIS_HOST = '127.0.0.1'
REDIS_PORT = 6379

# 密码登录
# REDIS_URL = 'redis://:password@IP:port'


